using UnityEngine;

namespace Locomotion
{
    public class JumpArrow : MonoBehaviour
    {
        [SerializeField] private Transform startTrans;
        [SerializeField] private Vector2 direction;
        [SerializeField] private float force;

        [SerializeField] private Transform arrowTransform;
        
        public Vector2 Velocity => force * direction;
        
        
        public void SetDirection(Vector2 targetDirection)
        {
            direction = targetDirection.normalized;
            UpdateArrow(startTrans.position, Velocity);
        }

        public void Hide()
        {
            transform.gameObject.SetActive(false);
        }

        public void Show()
        {
            transform.gameObject.SetActive(true);
        }
        
        public void UpdateArrow(Vector2 startPos, Vector2 jumpVelocity)
        {
            // 设置箭头的方向和大小
            float angle = Mathf.Atan2(jumpVelocity.y, jumpVelocity.x) * Mathf.Rad2Deg;
            Debug.Log($"arrow v: {jumpVelocity}, angle: {angle}");
            arrowTransform.position = transform.position;
            arrowTransform.rotation = Quaternion.Euler(0, 0, angle);
            // arrowTransform.localScale = new Vector3(jumpVelocity.magnitude, 1, 1);
            arrowTransform.localScale = new Vector3(1, 1, 1);
        }
    }
}